home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / DELPHI32 / COMPNENT / SAWIN95 / NONVIS.PAS < prev    next >
Pascal/Delphi Source File  |  1996-10-22  |  1KB  |  64 lines

  1. unit NonVis;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms;
  7.  
  8. type
  9.   TWindowedComponent = class(TComponent)
  10.   private
  11.     FHandle : THandle;
  12.     function GetHandle: THandle;
  13.     { Private declarations }
  14.   protected
  15.     procedure WndProc(var Msg : TMessage); virtual;
  16.     { Protected declarations }
  17.   public
  18.     function HandleAllocated: Boolean;
  19.     procedure HandleNeeded;
  20.     constructor Create(AOwner : TComponent); override;
  21.     destructor Destroy; override;
  22.     property Handle: THandle read GetHandle;
  23.   end;
  24.  
  25.  
  26. implementation
  27.  
  28. { TWindowedComponent }
  29.  
  30. constructor TWindowedComponent.Create(AOwner : TComponent);
  31. begin
  32.   inherited Create(AOwner);
  33.   FHandle := 0;
  34. end;
  35.  
  36. destructor TWindowedComponent.Destroy;
  37. begin
  38.   if HandleAllocated then DeAllocateHWnd(FHandle);
  39.   inherited Destroy;
  40. end;
  41.  
  42. function TWindowedComponent.HandleAllocated: Boolean;
  43. begin
  44.   Result := FHandle<>0;
  45. end;
  46.  
  47. procedure TWindowedComponent.HandleNeeded;
  48. begin
  49.   if not HandleAllocated then FHandle := AllocateHWnd(WndProc);
  50. end;
  51.  
  52. function TWindowedComponent.GetHandle: THandle;
  53. begin
  54.   HandleNeeded;
  55.   Result := FHandle;
  56. end;
  57.  
  58. procedure TWindowedComponent.WndProc(var Msg : TMessage);
  59. begin
  60.   Dispatch(Msg);
  61. end;
  62.  
  63. end.
  64.